package Group9.TodoManager.View;

import java.util.ResourceBundle;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;

import Group9.TodoManager.Settings;

/**
 * TodoManagerLookAndFeel class is used for introducing different look and feel
 * to main UI of the application
 * @author volkan cambazoglu
 *
 */
public class TodoManagerLookAndFeel {
    
    // MAKE IT SELECTABLE LIKE LANGUAGE SELECTION
    // null (default), "Metal", "System"
    private static String lookAndFeel;
    // "DefaultMetal", "TodoManager"
    private static String theme;

    /**
     * Default Constructor. Creates an instance of the class
     * Does basic initialization
     */
	public TodoManagerLookAndFeel(String tema) {
		super();
		if(tema.equalsIgnoreCase("DefaultTheme")){
			lookAndFeel = null;
		}
		else if(tema.equalsIgnoreCase("MetalTheme1")){
			lookAndFeel = "Metal";
			theme = "DefaultMetal";
		}
		else if(tema.equalsIgnoreCase("MetalTheme2")){
			lookAndFeel = "Metal";
			theme = "TodoManager";
		}
		else{
			lookAndFeel = "System";
		}
		setLookAndFeel();
	}

	/**
	 * Setter method for look and feel of the mainUI
	 */
	private void setLookAndFeel(){
    	String thisLookAndFeel = "";
    	
    	if(lookAndFeel != null){
    		if(lookAndFeel.equals("Metal")){
    			thisLookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
    		}
    		else if(lookAndFeel.equals("System")){
    			thisLookAndFeel = UIManager.getSystemLookAndFeelClassName();
    		}
    		
    		try {
				if(lookAndFeel.equals("Metal")){
					if(theme.equals("DefaultMetal")){
						MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
					}
					else if(theme.equals("TodoManager")){
						ResourceBundle themeResourceBundle = Settings.getThemeResourceBundle();
						MetalLookAndFeel.setCurrentTheme(new TodoManagerTheme(
								themeResourceBundle.getString("Primary1"), 
								themeResourceBundle.getString("Primary2"), 
								themeResourceBundle.getString("Primary3"), 
								themeResourceBundle.getString("Secondary1"), 
								themeResourceBundle.getString("Secondary2"), 
								themeResourceBundle.getString("Secondary3")));						
					}					
					UIManager.setLookAndFeel(new MetalLookAndFeel());
				}
				else{
					UIManager.setLookAndFeel(thisLookAndFeel);
				}
			} catch (ClassNotFoundException e) {
				System.err.println("setLookAndFeel: ClassNotFoundException");
			} catch (InstantiationException e) {
				System.err.println("setLookAndFeel: InstantiationException");
			} catch (IllegalAccessException e) {
				System.err.println("setLookAndFeel: IllegalAccessException");
			} catch (UnsupportedLookAndFeelException e) {
				System.err.println("setLookAndFeel: UnsupportedLookAndFeelException");
			}
    	}
	}
}
